//
//  QSUserInterface.m
//  DigitalEconomy_iOS
//
//  Created by Ding on 2020/3/23.
//  Copyright © 2020 DingC. All rights reserved.
//

#import "QSUserInterface.h"
#import "QSRequestManager.h"
#import "QSUploadImage.h"
#import "ApiMacro.h"
@implementation QSUserInterface

+ (void)checkPhoneWithPhone:(NSString *)phone
                   andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kUserCenter] stringByAppendingString:kCheckPhone];
       NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
       [bodyDic setObject:phone forKey:@"phone"];
    [QSRequestManager executeJSONTokenPOST:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            block(rspStatusAndMessage, responseDataDic);
        }
    }];
}



/**
 *@brief 判断当前版本是否需要更新
 * @param appFlag     类型 2 ios 1安卓
 *@param version  版本号
 */
+ (void)getNeedUpdateWithAppFlag:(NSString *)appFlag
                         Version:(NSString *)version
                        andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, QSNeedUpdateVersionModel *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kVersion];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:appFlag forKey:@"appFlag"];
    [bodyDic setObject:version forKey:@"version"];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            QSNeedUpdateVersionModel *model = [QSNeedUpdateVersionModel mj_objectWithKeyValues:responseDataDic];
            block(rspStatusAndMessage, model);
        }
    }];

    
}

+ (void)sendCodeWithPhone:(NSString *)phone
                 andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kUserCenter] stringByAppendingString:kSendCode];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:phone forKey:@"phone"];
     [QSRequestManager executeGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
         if (rspStatusAndMessage.code == kResponseSuccessCode  && responseDataDic) {
             block(rspStatusAndMessage, responseDataDic);
         }
     }];
}

+ (void)userLoginWithphone:(NSString *)phone
                 phoneCode:(NSString *)phoneCode
                  andBlock:(void (^)(ResponseMessage *, QSUserModel *))block {
    
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kUserCenter] stringByAppendingString:kLogin];;
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:phone forKey:@"phone"];
    [bodyDic setObject:phoneCode forKey:@"code"];
//    [bodyDic setObject:kDeviceUUIDString forKey:@"deviceId"];

    [QSRequestManager executeJSONTokenPOST:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        QSUserModel *user = nil;
        if (rspStatusAndMessage.code == kResponseSuccessCode  && responseDataDic) {
            user = [QSUserModel mj_objectWithKeyValues:responseDataDic];
        }
        block(rspStatusAndMessage,user);
    }];
}

+ (void)getUserisEnterprisePersonandBlock:(void (^)(ResponseMessage *, NSDictionary *))block {
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kGetSignCompanys];
     NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [QSRequestManager executeGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode  && responseDataDic) {
            block(rspStatusAndMessage, responseDataDic);
        }
    }];
}

/**
 * @brief 更改用户头像
 */
+ (void)changeUserImageWithImageUrl:(NSString *)imageUrl
                           AndBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kUserCenter] stringByAppendingString:kChangeUserIcon];
     NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    
    [bodyDic setValue:imageUrl forKey:@"headPic"];
    [QSRequestManager executeJSONTokenPOST:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            block(rspStatusAndMessage, responseDataDic);
        }
    }];
}

+ (void)logoutWithBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kUserCenter] stringByAppendingString:kLogOut];
     NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    
    [QSRequestManager executeJSONTokenPOST:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            block(rspStatusAndMessage, responseDataDic);
        }
    }];
}

/**
*@brief 获取绑定企业数量
*/
+ (void)getBundleCompanyNumWithEpAllCompany:(NSString *)epAllCompany
                                           AndBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kGetCompanyNum];
     NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setValue:epAllCompany forKey:@"epAllCompany"];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            block(rspStatusAndMessage, responseDataDic);
        }
    }];
}
@end
